<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Optimized CRC Computer</title>
<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../crc.html" title="Chapter 12. Boost.CRC 1.5">
<link rel="prev" href="crc_basic.html" title="Theoretical CRC Computer">
<link rel="next" href="crc_function.html" title="CRC Function">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
<td align="center"><a href="../../../index.html">Home</a></td>
<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="crc_basic.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../crc.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="crc_function.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="crc.crc_optimal"></a><a class="link" href="crc_optimal.html" title="Optimized CRC Computer">Optimized CRC Computer</a>
</h2></div></div></div>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">cstdint</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>  <span class="comment">// for boost::uintmax_t</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">cstddef</span><span class="special">&gt;</span>            <span class="comment">// for std::size_t</span>

<span class="keyword">namespace</span> <span class="identifier">boost</span>
<span class="special">{</span>
    <span class="keyword">template</span> <span class="special">&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">Bits</span><span class="special">,</span> <span class="identifier">uintmax_t</span> <span class="identifier">TruncPoly</span><span class="special">,</span> <span class="identifier">uintmax_t</span> <span class="identifier">InitRem</span><span class="special">,</span>
     <span class="identifier">uintmax_t</span> <span class="identifier">FinalXor</span><span class="special">,</span> <span class="keyword">bool</span> <span class="identifier">ReflectIn</span><span class="special">,</span> <span class="keyword">bool</span> <span class="identifier">ReflectRem</span> <span class="special">&gt;</span>
    <span class="keyword">class</span> <span class="identifier">crc_optimal</span><span class="special">;</span>
<span class="special">}</span>
</pre>
<p>
      The <span class="bold"><strong><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">crc_optimal</span></code></strong></span>
      class template acts as an unaugmented-CRC processor that can accept input at
      the byte-level. It takes all the Rocksoft™ Model CRC Algorithm parameters
      as template parameters. Like in <code class="computeroutput"><span class="identifier">crc_basic</span></code>,
      the <span class="emphasis"><em>WIDTH</em></span> stays as the first parameter and determines
      the built-in unsigned integer type used for division registers. The other Rocksoft™
      Model CRC Algorithm parameters move up to the template parameter field in the
      same relative order they were in the <code class="computeroutput"><span class="identifier">crc_basic</span></code>
      constructor. (Some parameters have defaults.) Objects based from <code class="computeroutput"><span class="identifier">crc_optimal</span></code> can either be default-constructed,
      giving it the same behavior as a <code class="computeroutput"><span class="identifier">crc_basic</span></code>
      object with the equivalent settings, or use one parameter, which overrides
      the initial remainder value<a href="#ftn.crc.crc_optimal.f0" class="footnote" name="crc.crc_optimal.f0"><sup class="footnote">[3]</sup></a> without permanently affecting the initial-remainder attribute.
    </p>
<p>
      Besides template parameters and construction, <code class="computeroutput"><span class="identifier">crc_optimal</span></code>
      differs from <code class="computeroutput"><span class="identifier">crc_basic</span></code> interface-wise
      by:
    </p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p class="simpara">
          Adding five class-static immutable data members corresponding to the new
          template parameters.
        </p>
<div class="table">
<a name="crc.crc_optimal.crc_optimal_rmca"></a><p class="title"><b>Table 12.3. Additional RMCA Expressions in boost::crc_optimal</b></p>
<div class="table-contents"><table class="table" summary="Additional RMCA Expressions in boost::crc_optimal">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>
                  <p>
                    New Member
                  </p>
                </th>
<th>
                  <p>
                    Equivalent
                  </p>
                </th>
</tr></thead>
<tbody>
<tr>
<td>
                  <p>
                    <code class="computeroutput"><span class="identifier">truncated_polynominal</span></code>
                  </p>
                </td>
<td>
                  <p>
                    <code class="computeroutput"><span class="identifier">get_truncated_polynominal</span></code>
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
                    <code class="computeroutput"><span class="identifier">initial_remainder</span></code>
                  </p>
                </td>
<td>
                  <p>
                    <code class="computeroutput"><span class="identifier">get_initial_remainder</span></code>
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
                    <code class="computeroutput"><span class="identifier">reflect_input</span></code>
                  </p>
                </td>
<td>
                  <p>
                    <code class="computeroutput"><span class="identifier">get_reflect_input</span></code>
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
                    <code class="computeroutput"><span class="identifier">reflect_remainder</span></code>
                  </p>
                </td>
<td>
                  <p>
                    <code class="computeroutput"><span class="identifier">get_reflect_remainder</span></code>
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
                    <code class="computeroutput"><span class="identifier">final_xor_value</span></code>
                  </p>
                </td>
<td>
                  <p>
                    <code class="computeroutput"><span class="identifier">get_final_xor_value</span></code>
                  </p>
                </td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break">
</li>
<li class="listitem">
          Removing the <code class="computeroutput"><span class="identifier">process_bit</span></code>
          and <code class="computeroutput"><span class="identifier">process_bits</span></code> member
          functions.
        </li>
<li class="listitem">
          Adding two versions of the <code class="computeroutput"><span class="keyword">operator</span>
          <span class="special">()</span></code> member function. The single-argument
          version forwards to <code class="computeroutput"><span class="identifier">process_byte</span></code>,
          making it suitable to STL algorithms that take (and possibly return) function
          objects<a href="#ftn.crc.crc_optimal.f1" class="footnote" name="crc.crc_optimal.f1"><sup class="footnote">[4]</sup></a>. The argument-less version forwards to <code class="computeroutput"><span class="identifier">checksum</span></code>,
          making it suitable for STL algorithms that expect generator objects<a href="#ftn.crc.crc_optimal.f2" class="footnote" name="crc.crc_optimal.f2"><sup class="footnote">[5]</sup></a>.
        </li>
<li class="listitem">
          Merging the two <code class="computeroutput"><span class="identifier">reset</span></code> member
          functions into one. (It uses a single parameter that can have a default
          argument).
        </li>
</ul></div>
<p>
      The major difference between <code class="computeroutput"><span class="identifier">crc_basic</span></code>
      and <code class="computeroutput"><span class="identifier">crc_optimal</span></code> is the internals.
      Objects from <code class="computeroutput"><span class="identifier">crc_basic</span></code> run
      their CRC algorithm one bit at a time, no matter which unit is used as input.
      Objects from <code class="computeroutput"><span class="identifier">crc_optimal</span></code>, when
      <span class="emphasis"><em>WIDTH</em></span> is at least <code class="computeroutput"><span class="identifier">CHAR_BIT</span></code><a href="#ftn.crc.crc_optimal.f3" class="footnote" name="crc.crc_optimal.f3"><sup class="footnote">[6]</sup></a>, use a byte-indexed table-driven CRC algorithm which is a <span class="bold"><strong>lot</strong></span> faster than processing individual bits.
    </p>
<p>
      Since all of the parameters are specified at compile-time, you cannot reuse
      a single computer object for separate runs with differing parameters. The type
      uses the automatically-defined copy/move/assign and destruction routines.
    </p>
<div class="footnotes">
<br><hr style="width:100; text-align:left;margin-left: 0">
<div id="ftn.crc.crc_optimal.f0" class="footnote"><p><a href="#crc.crc_optimal.f0" class="para"><sup class="para">[3] </sup></a>
        i.e. The interim-remainder before any input is read.
      </p></div>
<div id="ftn.crc.crc_optimal.f1" class="footnote"><p><a href="#crc.crc_optimal.f1" class="para"><sup class="para">[4] </sup></a>
            Like <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">for_each</span></code>.
          </p></div>
<div id="ftn.crc.crc_optimal.f2" class="footnote"><p><a href="#crc.crc_optimal.f2" class="para"><sup class="para">[5] </sup></a>
            Albeit this object won't change its return value within code that only
            uses it as a generator.
          </p></div>
<div id="ftn.crc.crc_optimal.f3" class="footnote"><p><a href="#crc.crc_optimal.f3" class="para"><sup class="para">[6] </sup></a>
        i.e. The optimizations are suspended if the <span class="emphasis"><em>WIDTH</em></span> only
        justifies using part of a single byte.
      </p></div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2001, 2003, 2012 Daryle Walker<p>
        Distributed under the Boost Software License, Version 1.0. (See the accompanying
        file LICENSE_1_0.txt or a copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="crc_basic.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../crc.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="crc_function.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
